﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Shell;
//using System.Windows.Forms;
namespace PhoneInfo.Page
{
    public partial class LexunMap : PhoneApplicationPage
    {
        private string url = null;
        public LexunMap()
        {
            InitializeComponent();

        }
        private Stack<Uri> NavigationStack = new Stack<Uri>();
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (App.appSitting.Theme == 1)
            {
                ApplicationBar = (ApplicationBar)this.Resources["AppBar"];
            }
            else
            {
                ApplicationBar = (ApplicationBar)this.Resources["AppBar1"];
            }
            IDictionary<string, string> parameters = this.NavigationContext.QueryString;
            if (parameters.ContainsKey("url"))
            {
                url = parameters["url"];
                if (parameters.ContainsKey("lxt"))
                {
                    url += "&lxt=" + parameters["lxt"];

                }
                else
                {
                    url += "&lxt=";
                }
                if (parameters.ContainsKey("vs"))
                {
                    url += "&vs=" + parameters["vs"];

                }
                else
                {
                    url += "&vs=1";
                }
                if (parameters.ContainsKey("cd"))
                {
                    url += "&cd=" + parameters["cd"];

                }
                else
                {
                    url += "&cd=854";
                }

            }
            else if (parameters.ContainsKey("businessUrl"))
            {
                url = parameters["businessUrl"];
                url += "&fw=";
                url += parameters["fw"];
                web.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
                return;
               // url= url.Replace("#","&");
            }
            else
            {
                url = "http://lexun.com/touch/index.aspx?vs=2&cd=1210";
            }
            web.Navigate(new Uri(url, UriKind.Absolute));
            
        }

        private void ApplicationBarIconButton1_Click(object sender, EventArgs e)
        {//刷新
            if (sender == null)
            {
                return;
            }
            if( PopShard.IsOpen ==true)
            {
                PopShard.IsOpen = false;
            }
            web.Navigate(new Uri(url, UriKind.Absolute));
        }

        private void ApplicationBarIconButton2_Click(object sender, EventArgs e)
        {//分享
            if (sender == null)
            {
                return;
            }
            //
            if (PopShard.IsOpen == true)
            {
                PopShard.IsOpen = false;
            }
            else
            {
                PopShard.IsOpen = true;
            }
            
         
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender==null)
            {
                return;
            }
            PopShard.IsOpen = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            SmsComposeTask sct = new SmsComposeTask();
            sct.Body = url;
　　        sct.Show();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            EmailComposeTask sct = new EmailComposeTask();
            sct.Body = url;
　　        sct.Show();
        }

        private void web_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            ProgBar.Visibility = Visibility.Collapsed;
            NavigationStack.Push(e.Uri);
        }

        private void web_Navigating(object sender, NavigatingEventArgs e)
        {
            ProgBar.Visibility = Visibility.Visible;  
        }
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (NavigationStack.Count > 1)
            {
                // get rid of the topmost item...
                NavigationStack.Pop();
                // now navigate to the next topmost item
                // note that this is another Pop - as when the navigate occurs a Push() will happen
                web.Navigate(NavigationStack.Pop());
                e.Cancel = true;
                return;
            }

            base.OnBackKeyPress(e);
        }

       

    }
}